<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            list-style: none;
            margin: 0;
            padding: 0;
        }

        #shop-car li {
            border: 1px dotted red;
            margin: 20px 0;
            padding: 20px;
        }

        .container {
            width: 400px;
            padding: 20px;
        }
        
    </style>
</head>

<body>
    <div class="container">
        <ul id="shop-car">
        </ul>
        <p id="totalnum">总数量：xxx</p>

    </div>
    <script src="./jquery.js"></script>
    <script src="./zuoye2.js"></script>
    <script>
        let str = '';
        for (let i = 0; i < products.length; i++) {
            str += `<li>\
                <input type="checkbox" >\
                <div>商品名称:${products[i].goods_name}</div>\
                <img src="${products[i].goods_img}" alt="">\
                <div>商品价格:${products[i].goods_price}</div>\
                <div class='num'>购买数量:${products[i].goods_num}</div>\
                <div>商品规格: ${products[i].goods_attr}</div>\
                <div class='select'>是否选中：${products[i].goods_is_checked ? '选中吧' : '不选中'}</div>\
            </li>`
        }
        $('ul').html(str);
        let inps=document.querySelectorAll('ul input');
        let divs=document.querySelectorAll('ul .select');
        let p=document.querySelector('p');
        inps[0].checked=true;
        p.innerHTML='总数量：'+ products[0].goods_num  ;
        for(let i=0;i<inps.length;i++){
            inps[i].onclick=function () {
                if (inps[0].checked == true && inps[1].checked == true) {
                    p.innerHTML='总数量：' + (products[0].goods_num + products[1].goods_num);
                    divs[0].innerHTML='是否选中：选中吧';
                    divs[1].innerHTML='是否选中：选中吧';
                } else if (inps[0].checked == true && inps[1].checked == false) {
                    divs[0].innerHTML='是否选中：选中吧';
                    divs[1].innerHTML='是否选中：不选中';
                    p.innerHTML='总数量：' + products[0].goods_num
                    console.log(2);
                } else if (inps[0].checked == false && inps[1].checked == true) {
                    divs[1].innerHTML='是否选中：选中吧';
                    divs[0].innerHTML='是否选中：不选中';
                    p.innerHTML='总数量：' + products[1].goods_num
                    console.log(3);
                } else {
                    p.innerHTML='总数量：xxx'  ;
                    divs[0].innerHTML='是否选中：不选中';
                    divs[1].innerHTML='是否选中：不选中'; 
                }
            }
        }
     


    </script>
</body>

</html>